package com.example.common.Interface.user.entity.vo;


import com.example.common.response.BizException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class AddressVO {
    private String streetAddress;

    private String city;

    private String state;

    private String country;

    private Integer zipCode;
    public String serialize() {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsString(this);
        }catch (Exception e){
            throw new BizException("序列化失败");
        }
    }

    // 反序列化方法，将 JSON 字符串转换为对象
    public static AddressVO deserialize(String json) {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.readValue(json, AddressVO.class);
        }catch (Exception e){
            throw new BizException("反序列化失败");
        }
    }
}
